import { getGuid } from '../../utils'

import { CustomComRender } from '../utils'
import { BwCustomComFrontTypeEnum } from '../enums'

import type {
  BwGetCustomComInfoFun,
  BwCustomComDesignInfoModel,
} from '../models'

export function createInsCom(
  design: BwCustomComDesignInfoModel,
  front: BwCustomComFrontTypeEnum,
  getCustomComInfo: BwGetCustomComInfoFun,
  extendUtils: Record<string, any>
) {
  return new Promise<void>((resolve, reject) => {
    const curIns = new CustomComRender({
      front: front ?? BwCustomComFrontTypeEnum.pc,
      getCustomComInfo,
      extendUtils,
    })

    curIns.setComCode(getGuid())
    curIns.setDesignInfo(design)
    const ele: any = curIns.getCom()
    resolve(ele)
  })
}
